﻿using System;
using System.ComponentModel.DataAnnotations;
using Viettel.VOFFICE.DAO.Enums;
using Viettel.VOFFICE.DAO.Helpers;
using Viettel.VOFFICE.DAO.Models;

namespace Viettel.VOFFICE.Web.Models
{
    public class BookModel : BaseModel
    {
        /// <summary>
        /// khởi tạo ko đối số, BUỘC PHẢI CÓ
        /// </summary>
        public BookModel()
        {
            CreatedAt = DateTime.Now;
            UpdatedAt = DateTime.Now;
            IsActive = true;
            IsDefault = false;
        }
        /// <summary>
        /// khởi tạo với book từ database
        /// </summary>
        /// <param name="book"></param>
        public BookModel(Book book)
        {
            Id = book.Id;
            Name = book.Name;
            Description = book.Description;
            BookType = book.BookType;
            CurrentNumber = book.CurrentNumber;
            Sequence = book.Sequence;
            IsActive = book.IsActive;
            IsDefault = book.IsDefault;
            Format = book.Format;
            ResetBy = book.ResetBy;
            OfficeIdUse = book.OfficeIdUse;
            CreatedAt = book.CreatedAt;
            UpdatedAt = book.UpdatedAt;
            CreatorId = book.CreatorId;
            if (book.v_Department != null)
            {
                OfficeNameUse = book.v_Department.Name;
            }
            BookTypeName = EnumHelper<BookType>.GetStringValue((BookType)book.BookType);
            if (book.ResetBy != null)
                ResetName = EnumHelper<BookResetType>.GetStringValue((BookResetType)book.ResetBy);
        }
        public int Id { get; set; }

        [Required(ErrorMessageResourceType = typeof(Resources.Resources), ErrorMessageResourceName = "region")]
        public string Name { get; set; }

        public string Description { get; set; }

        [Required(ErrorMessageResourceType = typeof(Resources.Resources), ErrorMessageResourceName = "region")]
        public byte BookType { get; set; }

        public string BookTypeName { get; set; }

        public int? CurrentNumber { get; set; }
        public int? Sequence { get; set; }
        public bool? IsActive { get; set; }
        public bool? IsDefault { get; set; }

        public string Format { get; set; }
        public byte? ResetBy { get; set; }
        public string ResetName { get; set; }

        [Required(ErrorMessageResourceType = typeof(Resources.Resources), ErrorMessageResourceName = "region")]
        public int? OfficeIdUse { get; set; }

        public string OfficeNameUse { get; set; }

        public DateTime CreatedAt { get; set; }
        public DateTime UpdatedAt { get; set; }

        /// <summary>
        /// người đang đăng nhập và tạo ra bản ghi này
        /// </summary>
        public Guid? CreatorId { get; set; }
        public string CreatorName { get; set; }

    }
}